<xsl:stylesheet version="1.1"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:math="http://exslt.org/math"
	xmlns="http://www.w3.org/2000/svg" 
	extension-element-prefixes="math">

	<xsl:import href="../../stylesheet.xslt" />
	<xsl:import href="tree.xslt" />

	<xsl:output method="xml" />

	<xsl:param name="orientation"/>	

	<xsl:template match="/">

		<xsl:call-template name="output-stylesheet-declaration" />
		
		<xsl:variable name="minx">
			<xsl:apply-templates select="part" mode="get-extent">
				<xsl:with-param name="direction" select="'west'"/>
			</xsl:apply-templates>
		</xsl:variable>

		<xsl:variable name="maxx">
			<xsl:apply-templates select="part" mode="get-extent">
				<xsl:with-param name="direction" select="'east'"/>
			</xsl:apply-templates>
		</xsl:variable>

		<xsl:variable name="miny">
			<xsl:apply-templates select="part" mode="get-extent">
				<xsl:with-param name="direction">north</xsl:with-param>
			</xsl:apply-templates>
		</xsl:variable>

		<xsl:variable name="maxy">
			<xsl:apply-templates select="part" mode="get-extent">
				<xsl:with-param name="direction">south</xsl:with-param>
			</xsl:apply-templates>
		</xsl:variable>

		<xsl:variable name="width" select="$maxx - $minx"/>
		<xsl:variable name="height" select="$maxy - $miny"/>
		<xsl:variable name="x" select="$minx"/>
		<xsl:variable name="y" select="$miny"/>
		
		<svg width="{$width}" height="{$height}" viewBox="{$x} {$y} {$width} {$height}">
		<xsl:message><xsl:value-of select="$minx"/>,<xsl:value-of select="$maxx"/></xsl:message>
			<g>
			<!-- 
				<defs>
					<filter id="outline-filter" filterUnits="userSpaceOnUse">
						<xsl:attribute name="width"><xsl:value-of
							select="$width" />px</xsl:attribute>
						<xsl:attribute name="height"><xsl:value-of
							select="$height" />px</xsl:attribute>
						<xsl:attribute name="x"><xsl:value-of
							select="$x" />px</xsl:attribute>
						<xsl:attribute name="y"><xsl:value-of
							select="$y" />px</xsl:attribute>

						<desc>outlines an object.</desc>
						<feMorphology result="DilateAlpha" radius="1"
							operator="dilate" in="SourceAlpha" />
						<feMerge>
							<feMergeNode in="DilateAlpha" />
							<feMergeNode in="SourceGraphic" />
						</feMerge>
					</filter>

				</defs>
 -->
			</g>
			
			<g>
				<xsl:apply-templates select="part" mode="render">
					<xsl:with-param name="orientation" select="$orientation"/>
				</xsl:apply-templates>
			</g>

		</svg>
	</xsl:template>

</xsl:stylesheet>